import Axios from 'axios'

let instance = Axios.create({
  baseURL: 'https://api.fangdafu.com:8031/',
  headers: {
    'Content-Type': 'multipart/form-data;charset=UTF-8'
  }
});

// 接口提交数据处理
instance.interceptors.request.use(request => {
  let token = window.location.search.replace('?token=','');

  request.headers.Authorization = token;

  // if (request.method === 'get') {
  //   request.url += getJsonToUrl(request.data);
  // }
  //
  // function getJsonToUrl(json) {
  //   let url = '?';
  //   for (let key in json) {
  //     const value = json[key];
  //     if (value !== '') {
  //       url += `${key}=${encodeURIComponent(value)}&`
  //     }
  //   }
  //   return url.substring(0, url.length - 1);
  // }

  // console.log(request);
  return request
});

// 接口返回数据处理
instance.interceptors.response.use(response => {
  // if (response.status === 200) {
  //   localStorage.clear()
  //   // Vue.$router.replace({name: 'Login'})
  // }

  return response
});

export default instance